#pragma once

#include "comm/my_defs.h"
#include "my_disk_vinfo.h"

typedef struct my_disk_index_s my_disk_index_t;

struct my_disk_index_s {
    my_disk_vinfo_t                 *vinfo;         // refer volume->vinfo

    int64_t                         slot_num;
    int64_t                         group_num;
    my_rwlock_t                     *group_locks;   // group_num rwlocks.
    int64_t                         *group_dirtys;  // group_num counters.
    int64_t                         bucket_num;
    int64_t                         *bucket_evict_slots;  // bucket_num.

    char                            *table;         // refer index table
    int64_t                         table_size;     // size of table
    char                            *flush_buf;     // flush buf, ONE_GROUP_SIZE

    my_bool_t                       open;
};

static inline void
my_disk_index_init(my_disk_index_t *index) {
    bzero(index, sizeof(my_disk_index_t));
}

void
my_disk_index_insert(my_disk_index_t *index, my_cache_key_t *key,
    my_disk_index_item_t *item);

my_bool_t
my_disk_index_lookup(my_disk_index_t *index, my_cache_key_t *key,
    my_disk_index_item_t *item);

my_bool_t
my_disk_index_remove(my_disk_index_t *index, my_cache_key_t *key);

my_bool_t
my_disk_index_open(my_disk_index_t *index, my_disk_vinfo_t *vinfo,
    char *table, int64_t table_size);

void
my_disk_index_close(my_disk_index_t *index);
